package com.huaxin.device.mapping;

import com.huaxin.device.dto.request.DeviceAlarmNotificationCreateReqDTO;
import com.huaxin.device.models.DeviceAlarmNotification;
import com.huaxin.hxenum.enums.NotificationReadStatus;
import com.huaxin.hxenum.enums.NotificationSendStatus;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;

import java.time.LocalDateTime;
import java.util.List;

@Mapper(componentModel = "spring")
public interface DeviceAlarmNotificationMapping {

    DeviceAlarmNotification toEntity(DeviceAlarmNotificationCreateReqDTO in);

    @AfterMapping
    default void afterMapping(DeviceAlarmNotificationCreateReqDTO in, @MappingTarget DeviceAlarmNotification entity) {
        entity.setSendStatus(NotificationSendStatus.PENDING);
        entity.setReadStatus(NotificationReadStatus.UNREAD);
        entity.setSendTime(LocalDateTime.now());
    }

    List<DeviceAlarmNotification> toEntityList(List<DeviceAlarmNotificationCreateReqDTO> in);
}